/*
 * @Description: 与业务耦合的自定义代码
 * @Date: 2023-10-31 10:53:30
 * @FilePath: \hksj-vued:\03code\hk-iot\src\utils\customService.ts
 */
import numeral from 'numeral';
import { useDicApi } from '/@/api/system/dic';
/**
 * @description: 根据后端返回的待审批信息类型，返回对应的中文名称
 * @param {number} resourceType
 */
export function getResourceType(resourceType: number) {
  switch (resourceType) {
    case 0:
      return '全部';
    case 1:
      return '医院项目信息';
    case 2:
      return '项目订单信息';
    case 3:
      return '销售提成管理';
    case 4:
      return '合作伙伴信息';
    case 5:
      return '战略资源数';
    case 6:
      return '专家资源数';
    default:
      return '其他';
  }
}

/**
 * @description: 根据字典id查询字典项
 * @param {string} typeId 字典id
 */
const queryDicListByTypeId = async (typeId: string) => {
  const { data } = await useDicApi().queryDicInfoAllByTypeId({
    typeId: typeId,
  });
  if (data?.children?.length) {
    let res = data.children.sort((a: any, b: any) => a.seq - b.seq);
    return res;
  } else if (data?.list?.length) {
    let res = data.list.sort((a: any, b: any) => a.seq - b.seq);
    return res;
  } else {
    return [];
  }
};

/**
 * @description: 格式化金额显示: 千分位显示，并且带两个小数点666,666.00
 * @param {string} number
 */
const formatNumber = (number: string | number) => {
  return numeral(number).format('0,0.00');
};


/**
 * 统一批量导出
 * @method getResourceType 根据后端返回的待审批信息类型，返回对应的中文名称
 */
const customService = {
  getResourceType: (resourceType: number) => {
    return getResourceType(resourceType);
  },
  queryDicListByTypeId,
  formatNumber
};
// 统一批量导出
export default customService;